﻿using KWT.DRG_DIP.DB;
using Microsoft.EntityFrameworkCore;

namespace KWT.DRG_DIP.API.Infrastructure
{
    public static class MultipleTenancyExtension
    {
        public static IServiceCollection AddConnectionByDatabase(this IServiceCollection services)
        {
            services.AddDbContext<EFContext>((serviceProvider, options) =>
            {
                var resolver = serviceProvider.GetRequiredService<IMySqlConnectionResolver>();
                string connStr = resolver.GetConnection();
                options.UseMySql(connStr, ServerVersion.AutoDetect(connStr));
                DapperHelper.connString = resolver.GetConnection();
            });

            return services;
        }
    }
}
